import $ from 'zepto'

export default function (router) {
  router.map({
    '/:code/:id': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/home': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/home/:code/:id': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/invite': {
      component (resolve) {
        require(['./views/invite'], resolve)
      }
    },
    '/log': {
      component (resolve) {
        require(['./views/log'], resolve)
      }
    },
    '/log/:code/:id': {
      component (resolve) {
        require(['./views/log'], resolve)
      }
    },
    '/user': {
      component (resolve) {
        require(['./views/home'], resolve)
      }
    },
    '/user/editAgent': {
      component (resolve) {
        require(['./views/user/editAgent'], resolve)
      }
    },
    '/user/tasks': {
      component (resolve) {
        require(['./views/user/tasks'], resolve)
      }
    },
    '/user/tasks/:p_id': {
      component (resolve) {
        require(['./views/user/tasks'], resolve)
      }
    },
    '/user/profile/': {
      component (resolve) {
        require(['./views/user/profile'], resolve)
      }
    },

    '/user/club/': {
      component (resolve) {
        require(['./views/user/club'], resolve)
      }
    },

    '/user/applyAudit/:club_id': {
      component (resolve) {
        require(['./views/user/applyAudit'], resolve)
      }
    },

     '/user/auditLog/:club_id': {
      component (resolve) {
        require(['./views/user/auditLog'], resolve)
      }
    },
     '/user/getClubRoom/:club_id': {
      component (resolve) {
        require(['./views/user/clubRoom'], resolve)
      }
    },
     '/user/getAllClubUser/:club_id': {
      component (resolve) {
        require(['./views/user/getAllClubUser'], resolve)
      }
    }
    ,
    '/user/createClub/': {
      component (resolve) {
        require(['./views/user/createClub'], resolve)
      }
    },
     '/user/updateClub/:club_id/:club_gems/:club_name': {
      component (resolve) {
        require(['./views/user/updateClub'], resolve)
      }
    },

    '/user/yeji/': {
      component (resolve) {
        require(['./views/user/yeji'], resolve)
      }
    },
    '/user/profile/:p_id': {
      component (resolve) {
        require(['./views/user/profile'], resolve)
      }
    },
    '/user/pay': {
      component (resolve) {
        require(['./views/user/pay'], resolve)
      }
    },
    '/user/pay/:path_id/:user_id/:money': {
      component (resolve) {
        require(['./views/user/pay'], resolve)
      }
    }
  })

  router.beforeEach(({to, from, next}) => {
    let toPath = to.path
    let fromPath = from.path
    console.log(`to: ${toPath} from: ${fromPath}`)
    if (toPath.replace(/[^/]/g, '').length > 1) {
      router.app.isIndex = false
    }
    else {
      let depath = toPath === '/' || toPath === '/invite' || toPath === '/rank'
      router.app.isIndex = depath ? 0 : 1
    }
    next()
  })

  router.afterEach(function ({to}) {
    console.log(`成功浏览到: ${to.path}`)
    $.refreshScroller()
  })
}
